import numpy as np
from Demos.SystemParametersInfo import x


#  3层 神经网络的实现

def sigmoid(x):
    return 1/(1+np.exp(-x))

def identity_function(x):
    return x


# #  A = XW + B
#
# X = np.array([1.0,0.5])
# W1 = np.array([[0.1,0.3,0.5],[0.2,0.4,0.6]])
# B1 = np.array([0.1,0.2,0.3])
#
# print(f"W1.shape:{W1.shape}")
# print(f"B1.shape:{B1.shape}")
# print(f"X.shape:{X.shape}")
#
# A1 = np.dot(X,W1)+B1
#
# print(f"A1.shape:{A1.shape}")
# print(f"A1={A1}")
#
# Z1 = sigmoid(A1)
#
# print(f"Z1={Z1}")
#
#
# W2 = np.array([[0.1,0.4],[0.2,0.5],[0.3,0.6]])
# B2 = np.array([0.1,0.2])
#
# print(f"W2.shape:{W2.shape}")
# print(f"B2.shape:{B2.shape}")
# print(f"Z1.shape:{Z1.shape}")
#
# A2 = np.dot(Z1,W2)+B2
#
# print(f"A2.shape:{A2.shape}")
# print(f"A2={A2}")
#
# Z2 = sigmoid(A2)
#
# print(f"Z2={Z2}")
#
# W3 = np.array([[0.1,0.3],[0.2,0.4]])
# B3 = np.array([0.1,0.2])
#
# print(f"W3.shape:{W3.shape}")
# print(f"B3.shape:{B3.shape}")
# print(f"Z2.shape:{Z2.shape}")
#
# A3 = np.dot(Z2,W3)+B3
#
# print(f"A3.shape:{A3.shape}")
# print(f"A3={A3}")
#
# Y = identity_function(A3)
#
# print(f"Y={Y}")


def init_network():
    network = {}
    network['w1'] = np.array([[0.1,0.3,0.5],[0.2,0.4,0.6]])
    network['w2'] = np.array([[0.1,0.4],[0.2,0.5],[0.3,0.6]])
    network['w3'] = np.array([[0.1,0.3],[0.2,0.4]])
    network['b1'] = np.array([0.1,0.2,0.3])
    network['b2'] = np.array([0.1,0.2])
    network['b3'] = np.array([0.1,0.2])

    return network

def forward(network, x):
    w1 = network['w1']
    w2 = network['w2']
    w3 = network['w3']
    b1 = network['b1']
    b2 = network['b2']
    b3 = network['b3']

    a1=np.dot(x,w1)+b1
    z1=sigmoid(a1)
    a2=np.dot(z1,w2)+b2
    z2=sigmoid(a2)
    a3=np.dot(z2,w3)+b3
    y=identity_function(a3)

    return y

network = init_network()
x = np.array([1.0,0.5])
y = forward(network, x)

print(y)


